#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sort(int* array, int nCnt)
{
    int max = array[0];
    int min = array[0];
    int nBase = 1;
    int* lpTmp;
    int Bucket[10] = { 0 };

    lpTmp = (int*)malloc(sizeof(int) * nCnt);
    if (!lpTmp) return;

    for (int i = 0; i < nCnt; i++)
    {
        if (array[i] > max)
            max = array[i];

        if (array[i] < min)
            min = array[i];
    }

    for (int i = 0; i < nCnt; i++)
        array[i] += abs(min);

    while (max / nBase > 0)
    {
        memset(Bucket, 0, sizeof(Bucket));

        for (int i = 0; i < nCnt; i++)
            Bucket[array[i] / nBase % 10]++;

        for (int i = 1; i < 10; i++)
            Bucket[i] += Bucket[i - 1];

        for (int i = nCnt - 1; i >= 0; i--)
        {
            lpTmp[Bucket[array[i] / nBase % 10] - 1] = array[i];
            Bucket[array[i] / nBase % 10]--;
        }

        for (int i = 0; i < nCnt; i++)
            array[i] = lpTmp[i];

        nBase *= 10;
    }

    free(lpTmp);

    for (int i = 0; i < nCnt; i++)
        array[i] -= abs(min);
}

int main()
{
    int array[9] = { 2,8,5,1,3,11,7,2,6 };

    sort(array, sizeof(array) / sizeof(int));

    for (unsigned int i = 0; i < (sizeof(array) / sizeof(int)); ++i)
        printf("%d ", array[i]);
    puts("");

    return 0;
}